package org.jfk.tbox.net;

import java.util.Date;

import org.apache.log4j.Logger;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.frame.FrameDecoder;
import org.jfk.core.utils.ByteUtils;

/**
 * 记录原始包内容
 * @author jxf
 * 2015年1月20日
 */
public class ShowLogFrameDecoder extends FrameDecoder{
	
	private static Logger logger = Logger.getLogger(ShowLogFrameDecoder.class);

	@Override
	protected Object decode(ChannelHandlerContext ctx, Channel channel,
			ChannelBuffer buffer) throws Exception {
		logger.info((new Date())+"::"+channel.getRemoteAddress()+"::"+ByteUtils.byteToHexString(buffer.array()));
		ChannelBuffer frame = ChannelBuffers.buffer(buffer.array().length);
		buffer.readBytes(frame);
		return frame;
	}
	
}
